package com.wthink.hzgj.bus

import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.viewModels
import com.wthink.hzgj.R
import com.wthink.hzgj.data.domain.BusDispatch
import com.wthink.hzgj.databinding.FragmentPlanBinding
import com.wthink.hzgj.util.NoBackFragment

class PlanFragment : NoBackFragment() {

    private val viewModel by viewModels<PlanViewModel>()

    private lateinit var binding: FragmentPlanBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = DataBindingUtil.inflate(
            inflater,
            R.layout.fragment_plan,
            container,
            false
        )

        arguments?.getParcelable<BusDispatch>("dispatch")?.let {
            viewModel.setBusDispatch(it)
        }

        binding.viewModel = viewModel
        binding.lifecycleOwner = this

        return binding.root
    }

    @RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

/*
        binding.okBtn.setOnClickListener {
            it.findNavController().popBackStack()
            (activity as MainNewActivity).busDispatch(arguments?.getParcelable<BusDispatch>("dispatch"))
        }
*/

        viewModel.start()
    }
}
